package com.tubi.ArraySearch;

public class kuaipai {
    public static void main(String[] args) {
        int[] arr = {6,1,2,7,8,3,9,5,4};

        kuaipai1(arr, 0, arr.length-1);

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i]+" ");
        }
    }

    private static void kuaipai1(int[] arr, int left, int right) {
        int left0 = left;
        int right0 = right;

        //计算出基准数
        int baseNumber = arr[left0];

        while (left != right){

            while (arr[right] >= baseNumber && right > left){
                right--;
            }

            while (arr[left] <= baseNumber && right >left){
                left ++;
            }

            int temp = arr[left];
            arr[left] = arr[right];
            arr[right] = temp;
        }

        int temp = arr[left];
        arr[left] = arr[left0];
        arr[left0] = temp;
    }
}
